package com.heima.estatemanagement.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.heima.estatemanagement.domain.TbParking;
import com.heima.estatemanagement.mapper.TbParkingMapper;
import com.heima.estatemanagement.service.TbParkingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.thymeleaf.util.StringUtils;
import tk.mybatis.mapper.util.StringUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 86191
 * @description 针对表【tb_parking(车位表)】的数据库操作Service实现
 * @createDate 2022-12-22 17:07:35
 */
@Service
public class TbParkingServiceImpl implements TbParkingService{

    @Autowired
    private TbParkingMapper parkingMapper;

    @Override
    public List<TbParking> findAll() {
        return parkingMapper.selectAll();
    }

    @Override
    public Page<TbParking> search(Map searchMap) {
        Map map=new HashMap();
//        if ((Integer)searchMap.get("pageNum")!=null){
//            pageNum=(int)searchMap.get("pageNum");

//        }
//        if ((Integer)searchMap.get("pageSize")!=null){
//            pageSize=(int)searchMap.get("pageSize");
//        }
        map.put("pageSize",searchMap.get("pageSize"));
        map.put("pageNum",searchMap.get("pageNum"));
        if(StringUtil.isNotEmpty((String) searchMap.get("LAY_demorange_s"))){
            map.put("LAY_demorange_s",searchMap.get("LAY_demorange_s"));
        }

        if(StringUtil.isNotEmpty((String) searchMap.get("LAY_demorange_e"))){
            map.put("LAY_demorange_e",searchMap.get("LAY_demorange_e"));
        }

        if (!StringUtils.isEmpty((String) searchMap.get("name"))){
            map.put("name",searchMap.get("name"));
        }

        if (!StringUtils.isEmpty((String) searchMap.get("community_id"))){
            map.put("community_id",searchMap.get("community_id"));
        }
        System.out.println(searchMap.get("community_id"));

        if (!StringUtils.isEmpty((String)searchMap.get("status"))){
            map.put("status",searchMap.get("status"));
        }

        if (!StringUtils.isEmpty((String)searchMap.get("switch"))){
            map.put("switch",searchMap.get("switch"));
        }

        Page<TbParking> search = parkingMapper.search(map);
        search.setTotal(parkingMapper.parkingCount(map));
        return search;
    }


    @Override
    public int add(TbParking parking) {
        return parkingMapper.add(parking);
    }

    @Override
    public TbParking findById(Integer id) {
        return parkingMapper.findById(id);
    }

    @Override
    public int update(TbParking parking) {
        return parkingMapper.update(parking);
    }

    @Override
    public Boolean del(List<Integer> ids) {
        for (Integer id : ids) {
            parkingMapper.deleteByPrimaryKey(id);
        }
        return true;
    }

    @Override
    public Boolean delById(int id) {
        return parkingMapper.delById(id);
    }

    @Override
    public boolean delFindByStatus(int id) {
        String str = parkingMapper.delFindByStatus(id);
        if (str == null) {
            return true;
        } else if (Integer.valueOf(str) < 0) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public List<TbParking> selectByCommunityId(int communityId) {
        return parkingMapper.selectByCommunityId(communityId);
    }


}
